package com.winbomb.kingcard;

import android.graphics.Color;
import android.util.Log;

public class GameMsg {

	private static final int MAX_MSG_BODY_COUNT = 10;

	/** 消息类型 */
	private int msgType;

	/** 消息的主题 */
	private String[] msgBodies;

	private int[] msgColors;

	private int msgCount;

	public GameMsg(int msgType) {
		this.msgType = msgType;
		this.msgCount = 0;

		this.msgBodies = new String[MAX_MSG_BODY_COUNT];
		this.msgColors = new int[MAX_MSG_BODY_COUNT];
	}

	/**
	 * 返回消息类型
	 * 
	 * @return
	 */
	public int getMsgType() {
		return this.msgType;
	}

	/**
	 * 返回消息体的长度
	 * 
	 * @return
	 */
	public int getMsgBodyCount() {
		return this.msgCount;
	}

	/**
	 * 返回第idx个消息
	 * 
	 * @param idx
	 * @return
	 */
	public String getMsgBody(int idx) {
		if (idx < 0 || idx >= msgCount) {
			return null;
		}

		return msgBodies[idx];
	}

	/**
	 * 返回消息体
	 * 
	 * @return
	 */
	public String[] getMsgBodies() {
		return this.msgBodies;
	}

	public int getMsgColor(int idx) {
		if (idx < 0 || idx >= msgCount) {
			return Color.WHITE;
		}

		return msgColors[idx];
	}

	/**
	 * 添加一条消息
	 * 
	 * @param msgBody
	 * @param msgColor
	 */
	public void add(String msgBody, int msgColor) {
		if (msgCount >= MAX_MSG_BODY_COUNT) {
			Log.w("GameMsg", "Reach max message body count.");
			return;
		}

		msgBodies[msgCount] = msgBody;
		msgColors[msgCount] = msgColor;
		msgCount++;
	}

	public void add(String msgBody) {
		add(msgBody, Color.WHITE);
	}

	public void addPlayer(String playerName) {
		add(playerName, Color.YELLOW);
	}

	public void addAction(Action action) {
		add(action.getName(), Color.BLUE);
	}
}